<template>
	<view>
		<view class="header">
			<view class="" style="display: flex;align-items: center;">
				<image src="@/static/zuos.png" mode="" style="width: 20upx;height: 35upx;" @click="back"></image>
				<text style="font-size: 30upx;margin-left: 30upx;color: #333;">{{zhiname}}</text>
			</view>
			<image src="../../static/jia.png" mode="" style="width: 40upx;height: 40upx;padding-right: 30upx;" @click="tosuai"></image>
		</view>
		<view class="nav">
			<view class="nav-tou">
				<view class="">
					<text style="font-size: 30upx;" :class="isshow ==1?'gg':'ggw'" @click="szh">推荐</text>
					<text style="margin-left: 50upx;font-size: 30upx;" :class="isshow ==2?'gg':'ggw'" @click="hehe">最新</text>
				</view>
				<view class="" style="display: flex;">
<!-- 					<view @click="tocity" class="hehe" style="margin-right: 20upx;">
						<text>长沙</text>
						<image src="@/static/to.png" mode="" style="width: 10upx;height: 10upx;padding-top: 10upx;">
						</image>
					</view> -->
					<view @click="more" class="hehe">
						<text>筛选</text>
						<image src="@/static/to.png" mode="" style="width: 10upx;height: 10upx;padding-top: 10upx;">
						</image>
					</view>
				</view>
			</view>
			<view class="nav-middle">
				<view class="zhiwei" @click.prevent.stop="detail(item.id)" v-for="item in list" v-if="list.length>0">
					<view style="flex-direction: row;justify-content: space-between;align-items: center;display: flex;" >
						<view class="z-tou">
							<text style="padding-left: 5upx;font-size: 32upx;font-weight: 550;">{{item.job_name}}</text>
							<text style="width: 60upx;height: 36upx;font-size: 24upx;background-color: #2687FF;color: #fff;display: inline-block;text-align: center;line-height: 36upx;margin-left: 17upx;border-radius: 5upx;" v-if="item.job_type==1">校招</text>
							<text v-else style="width: 60upx;height: 36upx;font-size: 24upx;background-color: #FFC600;color: #fff;display: inline-block;text-align: center;line-height: 36upx;margin-left: 17upx;border-radius: 5upx;">社招</text>
						</view>
						<text style="font-weight: normal;">{{item.min_salary}}k-{{item.max_salary}}k</text>
					</view>
					<view class="" style="padding-top: 30upx;">
						<text class="yaoqiu">{{item.educ_name}}</text>
						<text class="yaoqiu" style="margin: 20upx;">{{item.year}}</text>
					</view>
					<view
						style="flex-direction: row;justify-content: space-between;align-items: center;display: flex;padding: 20upx 0;padding-left: 5upx;">
						<text style="font-size: 28upx;color: #999999;">{{item.work_address}}</text>
										<view
							style="background-color: #F5F5F5;;width: 140upx;border-radius: 15upx;color: #999999;text-align: center;padding: 10upx;height: 60upx;" v-if="item.is_send==1">
							<text style="color: #999999;text-align: center;line-height: 44upx;">已投递</text>
						</view>
						<view
							style="background-color: #FF3D3D;width: 120upx;border-radius: 15upx;color: #FFFFFF;text-align: center;padding: 10upx;height: 60upx;line-height: 44upx;" v-else @click.prevent.stop="toudi(item)">
							<text style="color: #fff;">投递</text>
						</view>
					</view>
				</view>
				<view class="" v-if="list.length==0" style="font-size: 50upx;">没有该职位</view>
			</view>
			
		</view>
		<filter-popup :data="filterData" :form.sync="filterForm" v-model="popup.filter" title="全部筛选" height="1104rpx"
			@finsh="subFinsh"></filter-popup>
	</view>
</template>

<script>
import FilterPopup from "@/components/filter-popup/filter-popup";
	export default {
		data() {
			return {
				isZhi:false,
				zhilist: [],
				listData: [],
				zhiname:'更多职位',
				popup: {
					filter: false,
				},
				isshow:1,
				//筛选表单数据
				filterData: [{
						children: false, //是否有子项
				 	title: "意向度",
						key: "intention_type", //键名 接收对象名字
						keyValue: "value", //获取的值是哪个
				  isRadio: true, //是否单选 否则多选
						data: [{
							"id": 386,
							"title": "这啥",
							"cate_id": 371,
							"value": 0
						}, {
							"id": 387,
							"title": "我很烦",
							"cate_id": 371,
							"value": 1
						}, {
							"id": 388,
							"title": "第三个",
							"cate_id": 371,
							"value": 2
						}],
					},
					{
						children: false, //是否有子项
						title: "手机号码",
						key: "is_bind_phone", //键名 接收对象名字
						keyValue: "value", //获取的值是哪个
						isRadio: true, //是否单选 否则多选
						data: [{
								title: "未绑定",
								value: 0,
							},
							{
								title: "已绑定",
								value: 1,
							},
						],
					},
					{
						children: false, //是否有子项
						title: "企微好友",
						key: "is_work_customer", //键名 接收对象名字
						keyValue: "value", //获取的值是哪个
						isRadio: true, //是否单选 否则多选
						data: [{
								title: "未添加",
								value: 0,
							},
							{
								title: "已添加",
								value: 1,
							},
						],
					},
					{
						children: true, //是否有子项
						isRadio: false, //是否单选
						title: "标签内容",
						key: "label", //键名 接收对象名字
						keyValue: "id", //获取的值是哪个
						data: [{
								title: "客户重要程度",
								id: 22,
								children: [{
										title: "一般意向2",
										id: 32,
										value: 1,
									},
									{
										title: "一般意向3",
				 					id: 12,
										value: 1,
									},
				  		],
							},
							{
								title: "客户重要程度2",
								id: 122,
								children: [{
										title: "一般意向2",
										id: 43,
										value: 1,
				 				},
									{
										title: "一般意向3",
										id: 23,
										value: 1,
									},
								],
							},
						],
					},
				], //筛选数据
				filterForm: {}, //选中的表单
				cateid:'',
				zhanid:'',
				list:[],
				userInfos:{},
				edu_id:'',
				year_id:'',
				welfares_id:'',
				salary_num:'',
			}
		},
		
		onLoad(option) {
			try {
				const value = uni.getStorageSync('userInfo');
				if (value) {
					this.userInfos = JSON.parse(value)
				}
			} catch (e) {
				// error
			}
			uni.request({
				url: 'https://dsx.cdzer.com/api/Job/getposition', //仅为示例，并非真实接口地址。
				method: 'POST',
				header: {
					'content-type': 'application/x-www-form-urlencoded',
				},
				success: (res) => {
					console.log(res, "职位分类列表")
					this.zhilist = res.data.data
				}
			});
			if(option.zhiname){
				this.zhiname = option.zhiname
			}else{
				this.zhiname = '更多职位'
			}
			this.cateid = option.cateid
			this.zhanid = option.zhanid
			if(option.jobid){
				var jobid = option.jobid
			}else{
				var jobid = ''
			}
			uni.request({
				url: 'https://dsx.cdzer.com/api/Circle/getcirclejob', //仅为示例，并非真实接口地址。
				method: 'POST',
				data:{
					circle_id:option.zhanid,
					position_type:jobid,
					uid:this.userInfos.id,
					type:1,
				},
				header: {
					'content-type': 'application/x-www-form-urlencoded',
				},
				success: (res) => {
					console.log(res, "职位推荐列表")
					this.list = res.data.data
				}
			});
		},
		methods: {
			toudi(item){
				if(JSON.stringify(this.userInfos) == '{}'){
					uni.showModal({
					
						title: '提示',
					
						content: "你还未登录，是否前往登录页面",
					
						success: function(res) {
					
							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url: '/pagesB/login/login'
								})
							} else if (res.cancel) {
					
								console.log('用户点击取消');
					
							}
					
						}
					
					});
				}else if(this.userInfos.shop_id>0){
					var that = this
					uni.showModal({
					
						title: '提示',
					
						content: "商家无法投递简历",
					
						success: function(res) {
					
							if (res.confirm) {
								console.log('用户点击确定');
					
							} else if (res.cancel) {
					
								console.log('用户点击取消');
					
							}
					
						}
					
					});
				}else{
					uni.request({
						url: 'http://dsx.cdzer.com/api/Job/apply_job', //仅为示例，并非真实接口地址。
						method: 'POST',
						data:{
							job_id:item.id,
							shop_id:item.shop_id,
							uid:this.userInfos.id
						},
						header: {
							'content-type': 'application/x-www-form-urlencoded',
						},
						success: (res) => {
							console.log(res,"投递")
							if(res.data.status==200){
								uni.showToast({
									title:res.data.mess,
									icon:'none'
								})
								this.szh()
							}else{
								var that = this
								uni.showModal({
								
									title: '提示',
								
									content: "是否前往个人中心完善简历信息",
								
									success: function(res) {
								
										if (res.confirm) {
											uni.switchTab({
												url:'/pages/tabBar/mydetail'
											})
											console.log('用户点击确定');
								
										} else if (res.cancel) {
								
											console.log('用户点击取消');
								
										}
								
									}
								
								});
							}
						}
					});
				}
			},
			subFinsh(e) {
				console.log("this.filterForm :>> ", this.filterForm);
				console.log("返回参数数组 和 this.filterForm 相等 :>> ", e.intention_type0,this.filterData);
				if(e.intention_type1.length>0){	
					this.edu_id = this.filterData[1].data[e.intention_type1].id
				}
				if(e.intention_type2.length>0){
					this.year_id = this.filterData[2].data[e.intention_type2].id
				}
				if(e.intention_type4.length>0){
					this.welfares_id = this.filterData[4].data[e.intention_type4].id
				}
				if(e.intention_type1.length==0&&e.intention_type2.length==0&&e.intention_type4.length==0){
					if(this.jobid == undefined ){
						this.jobid = ''
					}
					uni.request({
						url: 'https://dsx.cdzer.com/api/Circle/getcirclejob', //仅为示例，并非真实接口地址。
						method: 'POST',
						data:{
							circle_id:this.zhanid,
							position_type:this.jobid,
							uid:this.userInfos.id,
							type:1,
						},
						header: {
							'content-type': 'application/x-www-form-urlencoded',
						},
						success: (res) => {
							console.log(res, "职位推荐列表")
							this.list = res.data.data
						}
					});
				}else{
					uni.request({
						url: 'https://dsx.cdzer.com/api/Circle/getcirclejob', //仅为示例，并非真实接口地址。
						method: 'POST',
						data:{
							circle_id:this.zhanid,
							type:1,
							uid:this.userInfos.id,
							edu_id:this.edu_id,
							year_id:this.year_id,
							welfares_id:this.welfares_id,
							salary_num:this.salary_num
						},
						header: {
							'content-type': 'application/x-www-form-urlencoded',
						},
						success: (res) => {
							console.log(res, "职位推荐列表")
							this.list = res.data.data
						}
					});
				}
				console.log(this.edu_id,"教育id",this.year_id,"年限id",this.welfares_id,"福利id")
				
			},
			more(){
				//话题筛选
				uni.request({
					url: 'https://dsx.cdzer.com/api/Job/get_job_conditions', //仅为示例，并非真实接口地址。
					method: 'POST',
					data:{
						cate_id:this.cateid
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded',
					},
					success: (res) => {
						console.log(res, "zhaopin筛选列表")
						this.filterData = res.data.data	
						
					}
				});
				this.popup.filter = true
				
			},
			tosuai(){
				uni.navigateTo({
					url:`./zwsuai?cateid=${this.cateid}&zhanid=${this.zhanid}`
				})
			},
			szh(){
				uni.request({
					url: 'https://dsx.cdzer.com/api/Circle/getcirclejob', //仅为示例，并非真实接口地址。
					method: 'POST',
					data:{
						circle_id:this.zhanid,
						type:1,
						uid:this.userInfos.id
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded',
					},
					success: (res) => {
						console.log(res, "职位推荐列表")
						this.list = res.data.data
					}
				});
				this.isshow = 1
			},
			hehe(){
				uni.request({
					url: 'https://dsx.cdzer.com/api/Circle/getcirclejob', //仅为示例，并非真实接口地址。
					method: 'POST',
					data:{
						circle_id:this.zhanid,
						type:2,
						uid:this.userInfos.id
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded',
					},
					success: (res) => {
						console.log(res, "职位推荐列表")
						this.list = res.data.data
					}
				});
				this.isshow = 2
			},
			back(){
				uni.navigateBack({
					delta:1
				})
			},
			detail(id){
				uni.navigateTo({
					url:`./zhidetail?id=${id}`
				})
			},
			confiremJob(e) {
				console.log(e)
				this.zhiname = e.name
				this.isZhi = false	
				// this.position_id = e.id
			
			},
			show(id) {	
				this.zhiweiId = id
				uni.request({
					url: 'https://dsx.cdzer.com/api/Job/getpositionlist', //仅为示例，并非真实接口地址。
					method: 'POST',
					data: {
						cate_id: id
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded',
					},
					success: (res) => {
						console.log(res, "岗位列表")
						if (res.data.status == 200) {
							this.listData = res.data.data
							this.$refs.jobSelect.show()
						}
					}
				});
			},
		}
	}
</script>
<style lang="scss">
	.ggw{
		color: #999999;
	}
	.gg{
		color: #000;
	}

	.nav-tou {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.nav-middle {
		/* background-color: #fff; */
		margin-top: 40upx;
		padding-bottom: 40upx;
	}

	.hehe {
		width: 120upx;
		display: flex;
		align-items: center;
		justify-content: center;
		height: 60upx;
		background: #EEEEEE;
		border-radius: 10upx;
		color: #666666;
	}

	.zhiwei {
		padding: 20upx 10upx;
		background-color: #fff;
		/* width: 94%; */
		margin: 0 auto;
		border-radius: 12upx;
		margin-top: 10upx;
	}

	.yaoqiu {
		height: 45upx;
		display: inline-block;
		background-color: #f5f5f5;
		text-align: center;
		line-height: 45upx;
		padding: 15upx;
		padding-left: 24upx;
		padding-right: 24upx;
		border-radius: 12upx;
		color: #666666;
	}

	.nav {
		padding: 30upx;
		margin-top: 120upx;
	}

	.header {
		position: fixed;
		background-color: #fff;
		height: 110upx;
		width: 100%;
		top: 0;
		left: 0;
		display: flex;
		z-index: 100;
		align-items: center;
		padding-left: 30upx;
		justify-content: space-between;
	}
</style>
